package com.cloudfun.campusshare.common.constant;

/**
 * Created by linyangping on 2019/10/21
 */
public enum Code {
    //通用部分
    UNDEFINED(-1, "未定义"),
    SUCCESS(0, "成功"),
    ERROR(1, "失败"),

    // user start(1000-2000)
    AGREEMENT(1001, "未勾选协议"),
    ACCOUNT_FROZEN(1002, "账户被冻结"),
    PHONE_EXIST(1003, "手机号已被注册"),
    UNAUTH(1004, "用户未注册区块链账户"),
    KEY_DOWNLOAD(1005, "用户已下载过密钥"),
    USER_EMAIL_EXIST(1006, "用户已绑定邮箱"),
    USERNAME_EXIST(1007, "用户名已存在"),
    PASSWORD_DIFF(1008, "两次密码不一致"),
    EMAIL_EXIST(1009, "邮箱已被注册"),
    USER_UNAUTH(1010, "用户未认证"),
    PHONE_SAME(1011, "该手机号码与原手机号码相同"),
    PHONE_UNEXIST(1012, "手机号码未注册"),
    ACCOUNT_JSON_ERROR(1013, "用户私钥错误"),
    EMAIL_ERROR(1014, "邮件发送失败"),
    ERROR_PASSWORD_ACCOUNT(1015, "账号或密码错误"),
    PASSWORD_SAME(1016, "新密码与原密码一致"),
    ERROR_PASSWORD_OLD(1017, "原密码不正确"),
    AUTHENTICATION_REQUIRE(1018, "用户未登陆"),
    ENTERPRISE_NAME_EXISTS(1019, "企业已存在"),
    ROLE_AUTHORITY_IS_MISSING(1020,"角色没有设置权限"),
    ADD_SELF_AS_SUB(1021,"不能添加自己为子账号"),
    ADD_REPEAT_SUB(1022,"子账号已存在"),
    //user end


    // contract start(2000-3000)
    NOAUTH(2002, "没权限"),
    NODATA(2003, "数据不存在"),
    DATA_EXIST(2004, "数据已存在"),
    SHOW_HEADPAGE_AUTHORITY_MISSING(2005,"非运营商，不允许展示首页"),
    // contract end(2000-3000)


    // device start(3000-4000)
    DEVICE_IS_BOUND(3001, "设备已经被绑定"),
    DEVICE_NOT_EXIST(3002, "设备不存在"),
    DEVICE_PERMISSION_DENIED(3003, "没有设备权限"),
    EVI_NOT_EXIST(3004, "未找到与哈希匹配的存证！"),
    CODE_NOT_FILLED(3005, "存证的提取码未填写！"),
    CODE_PE(3006, "提取口令格式错误！"),
    CODE_ERROR(3007, "提取口令不存在！"),
    HASH_NOT_FILLED(3008, "数字存证哈希未填写！"),
    HASH_PE(3009, "存证哈希格式错误！"),
    DEVICE_OFFLINE(3010, "设备离线！"),
    DEVICE_RUNNING(3011, "设备正在运行！"),
    DEVICE_NOT_BOUND(3012, "设备未绑定"),
    DEVICE_ABNORMAL(3013, "设备异常"),
    RELETE_DEVICE_ERROR(3014,"关联设备并非加液器"),
    RELETE_ABOVE_ONCE(3015,"该设备已关联"),
    NEED_RELETE_AHEAD(3016,"需要先解除该设备的关联,再尝试解绑"),
    //device end

    //verift code start(4000-5000)
//    VERIFY_CODE_UNEXIST(4001, "验证码不存在"),
    VERIFY_CODE_OVERDUE(4002, "验证码过期"),
    VERIFY_CODE_ERROR(4003, "验证码错误"),
    KEY_UNEXIST(4004, "口令不存在"),
    KEY_ERROR(4005, "口令错误"),
    LINK_ERROR(4006, "链接错误"),
    //verift code end(4000-5000)

    // blockchain start(5001-6000)
    BLOCKCHAIN_NOT_EXIST(5001, "区块链不存在"),
    CONTRACR_NAME_EXIST(5002, "合约标示已存在"),
    CONTRACR_NOT_EXIST(5003, "合约不存在"),
    BLOCKCHAIN_EXIST(5004, "该区块链名称已存在"),
    // blockchain end

    // attachment start(6000-7000)
    BUCKET_EXIST(6001, "桶已存在"),
    BUCKET_NOT_EXIST(6002, "桶不存在"),
    FILE_EXIST(6003, "文件已存在"),
    FILE_NOT_EXIST(6004, "文件不存在"),

    TYPE_EXIST(6005, "附件类型已存在"),
    TYPE_NOT_EXIST(6006, "附件类型不存在"),
    ORGAN_TYPE_NOT_EXIST(6007, "企业与附件类型关联不存在"),
    FILE_UPLOAD_ERROR(6008, "附件上传失败，请稍后再试"),
    // attachment end

    // app start
    APP_NOT_FOUND(7001, "应用不存在"),
    APP_KEY_NOT_FOUND(7002, "APP KEY不存在"),
    APP_TOKEN_NOT_FOUND(7003, "请获取app口令"),
    APP_PHONE_VERIFY_FAIL(7004, "手机号信息有误"),
    APP_NAME_EXIST(7005, "该应用名称已存在"),
    APP_KEY_OR_SECRET_ERROR(7006, "APP KEY或APP SERCET 有误"),
    APP_PERMISSION_DENIED(7007, "没有权限"),
    // app end

    EXPORT_ERROR(8000,"文件导出异常"),
    PARAMETER_ERROR(8001, "参数校验异常"),
    PARAMETER_NOT_READABLE(8002, "参数类型错误"),

    PERMISSION_DENIED(9001, "权限拒绝"),
    UNKNOWN_ABNORMAL(9002, "未知异常"),
    INVALID_USER(9003, "账户不存在"),
    ACCOUNT_KEY_EMPTY(9004, "用户名为空"),
    ACCOUNT_ALREADY_EXIST(9005, "用户名已存在"),
    ERROR_PASSWORD(9006, "密码错误"),
    PASSWORD_ERROR_TIME_OVER(9007, "由于密码输入错误多次，您的账号将被冻结5分钟"),
    ACCOUNT_STILL_LOCK(9008, "该账号已被冻结"),

    TOKEN_FORMAT_ERROR(9009, "token格式错误，不是有效token"),
    TOKEN_INVALID(9010, "token过期"),
    TOKEN_CRYPT_ERROR(9011, "token加解密异常"),
    TOKEN_AUTH_ERROR(9012, "您还未认证，请先认证"),
    TOKEN_ERROR(9013, "token异常"),

    ACCOUNT_DISABLED(9014, "该账号已被禁用"),

    HYPERCHAIN_ERROR(9100, "区块链异常"),

    JSON_TRANSFER_ERROR(9200, "JSON转化异常"),

    CLIENT_NOT_REGISTER(9300, "业务系统未注册"),
    CLIENT_ALREADY_REGISTER(9301, "业务系统已注册"),

    CLIENT_ROLE_NOT_EXIST(9400, "该业务系统该角色不存在"),

    SYSTEM_ERROR(9999, "系统异常，请稍后重试"),

    // contract start
    CONTRACT_IS_NOT_EXIST(10000, "合约不存在"),
    READ_CONTRACT_ADDRESS_FAIL(10001, "读取合约地址失败"),
    UPDATE_CONTRACT_FAIL(10002, "更新合约失败"),
    DEPLOY_CONTRACT_FAIL(10003, "部署合约失败"),
    // contract end

    // application start
    DUPLICATE_APPLICATION(11001, "请勿重复提交申请"),
    // application end

    // msg start
    MSG_UNREAD(12001, "消息未读"),
    // msg end

    // user auth start
    USER_AUTH_SUCCEED(13001, "已认证成功，请勿重复认证"),
    USER_AUTH_APPLIED(13002, "已提交认证中，请勿重复提交"),
    // user auth end


    //cash advance start
    REPEAT_ACTION(15001, "您今天已经发起过提现，请明天再尝试哦"),
    NOT_PASS_YET(15002, "您还有提现申请未通过，暂时无法再次体现"),
    //cash advance end

    // device  start
    ALREADY_IN_USE(16001, "该设备已被占用"),
    HAVE_IN_PROGRESS_ORDER(16002, "当前有正在进行的订单"),
    DEVICE_NOT_AVAILABLE(16003, "设备不可用"),
    PLATFORM_ERROR(16004,"设备平台错误"),
    // device  end

    // promotion start
    ONLINE_PROMOTION_CAN_NOT_DELETED(17001, "无法删除正在进行中的活动,请先下线活动"),
    // promotion end


    // device order generate
    NOT_IN_SERVICE_TIME(18001,"不在设备服务时间之内"),
    SCAN_WRONG_DEVICE(18002,"扫错设备"),
    ORDER_DEVICE_COUNT_OVERFLOW(18003,"预约设备数量超出限制"),
    NOT_IN_USE_JOIN_QUEUE(18004,"排队时设备没有被占用"),



    //宝付支付
    USER_NOT_AUTH_WE_CHAT(19000,"用户没有授权"),
    //Announcement
    ANNOUNCEMENT_TIME_OVER(20000,"在该时间段内，已有3条公告,届时可能无法正常上线：{0}");
    ;


    private int code;
    private String msg;

    // 构造方法
    Code(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public static String getMsgByCodeInt(int codeInt) {
        for (Code e : Code.values()) {
            if (e.getCode() == codeInt) {
                return e.msg;
            }
        }
        throw new IllegalArgumentException("未定义的code码:" + codeInt);
    }

    public static Code getCodeByCodeInt(int codeInt) {
        for (Code code : Code.values()) {
            if (code.getCode() == codeInt) {
                return code;
            }
        }
        throw new IllegalArgumentException("未定义的code码:" + codeInt);
    }


}
